var app = getApp();
const pathUrl = app.globalData.pathUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pathUrl: pathUrl,
    openId: '',
    queryResults: '',
    violationTimes: '',
    totalDeduction: '',
    totalFine: '',//总罚款
    list: ' ',
    ocrName: '', //ocr姓名
    ocrSex: '', //ocr性别
    ocrNation: '', //ocr民族
    ocrBirth: '', //ocr出生
    ocrAddress: '', //ocr地址
    ocrIdNumber: '', //ocr身份证号
    ocrOffice: '', //ocr签发机关
    ocrValidityPeriod: '', //ocr有效期限
    cusIdValidfrom: '', //证件开始日期
    cusIdValidto: '', //证件结束日期
    brand: '', //品牌/车型
    plateNumber: '', //车牌号
    holder: '', //所有人
    dateIssue: '', //注册/发证日期
    nature: '', //使用性质
    address: '', //住址
    vinno: '', //车架号
    engineNumber: '', //发动机号
    residentialAddress: '', //居住地址
    telephone: '', //联系电话
    checkedValue: '', //婚姻情况
    spouseName: '', //配偶姓名
    spouseTelephone: '', //联系电话
    urgent: '', //紧急联系人
    urgentTelephone: '', //紧急联系人联系电话
    urgent2: '', //紧急联系人
    urgentTelephone2: '', //紧急联系人联系电话
    isSubmit: true, //防止重复提交
    guaranteeName: '', //担保人姓名
    guaranteeIdCard: '', //担保人身份照
    guaranteePhone: '', //担保人电话
    orderAmount: '', //金额
    pickerIndex: '3',//选择期数index
    orderPeriod: '36',//期数
    orderBy6: '',
    orderBy7: '',
    orderBy8: '',
    orderBy4: '',
    orderBy5: '',
    // hidden: true,
    // btnValue: '',
    // btnDisabled: false,
    // name: '',
    // phone: '',
    // code: '',
    // second: 60
  },

  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  //预留
  yuliuInput: function (e) {
    this.setData({
      yuliu: e.detail.value
    })
  },
  //银行代码
  bankCodeInput: function (e) {
    this.setData({
      bankCode: e.detail.value
    })
  },
  //银行卡号
  accountNoInput: function (e) {
    this.setData({
      accountNo: e.detail.value
    })
  },
  //电话
  mobileInput: function (e) {
    var val = e.detail.value;
    this.setData({
      mobile: val
    })
    if (val != '') {
      this.setData({
        hidden: false,
        btnValue: '获取验证码'
      })
    } else {
      this.setData({
        hidden: true
      })
    }
  },
  //验证码输入
  bindCodeInput(e) {
    this.setData({
      code: e.detail.value
    })
  },
  //名字赋值
  nameInput: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  //身份证号
  IdCardInput: function (e) {
    this.setData({
      IdCard: e.detail.value
    })
  },
  orderBy6Input: function (e) {
    this.setData({
      orderBy6: e.detail.value
    })
  },
  //
  orderBy7Input: function (e) {
    this.setData({
      orderBy7: e.detail.value
    })
  },  //
  orderBy8Input: function (e) {
    this.setData({
      orderBy8: e.detail.value
    })
  },
  //储蓄卡
  orderBy9Input: function (e) {
    this.setData({
      orderBy9: e.detail.value
    })
  },
  //开户行
  orderBy10Input: function (e) {
    this.setData({
      orderBy10: e.detail.value
    })
  },
  //银行预留电话
  orderBy11Input: function (e) {
    this.setData({
      orderBy11: e.detail.value
    })
  },
  //获取短信验证码
  // getCode(e) {
  //   console.log('获取验证码');
  //   var that = this;
  //   zhenzisms.client.init('https://sms_developer.zhenzikj.com', 'appId', 'appSecret');
  //   zhenzisms.client.send(function (res) {
  //     if (res.data.code == 0) {
  //       that.timer();
  //       return;
  //     }
  //     wx.showToast({
  //       title: res.data.data,
  //       icon: 'none',
  //       duration: 2000
  //     })
  //   }, '15811111111', '验证码为:3322');

  // },
  // timer: function () {
  //   let promise = new Promise((resolve, reject) => {
  //     let setTimer = setInterval(
  //       () => {
  //         var second = this.data.second - 1;
  //         this.setData({
  //           second: second,
  //           btnValue: second + '秒',
  //           btnDisabled: true
  //         })
  //         if (this.data.second <= 0) {
  //           this.setData({
  //             second: 60,
  //             btnValue: '获取验证码',
  //             btnDisabled: false
  //           })
  //           resolve(setTimer)
  //         }
  //       }
  //       , 1000)
  //   })
  //   promise.then((setTimer) => {
  //     clearInterval(setTimer)
  //   })
  // },

 
  submitBtn: function () {
    var that = this;
    var name = that.data.name;
    var accountNo = that.data.accountNo;
    var mobile = that.data.mobile;
    var bankCode = that.data.bankCode;
    var IdCard = that.data.IdCard;
    var yuliu =that.data.yuliu;
    if (name == " " || name == null) {
      wx.showModal({
        title: '提示',
        content: '请填写姓名',
        showCancel: false,
      })
      return false;
    }
    if (IdCard == " " || IdCard == null) {
      wx.showModal({
        title: '提示',
        content: '请填写身份证号',
        showCancel: false,
      })
      return false;
    }
    if (accountNo == " " || accountNo == null) {
      wx.showModal({
        title: '提示',
        content: '请填写银行卡号',
        showCancel: false,
      })
      return false;
    }
    if (bankCode == " " || bankCode == null) {
      wx.showModal({
        title: '提示',
        content: '请填写银行代码',
        showCancel: false,
      })
      return false;
    }
    if (mobile == " " || mobile == null) {
      wx.showModal({
        title: '提示',
        content: '请填写电话',
        showCancel: false,
      })
      return false;
    }

    wx.request({
      url: pathUrl + '/rest/fk/dotdqy',
      data: {
        realName: that.data.name,
        cardNo: that.data.IdCard,
        bankCardNo: that.data.accountNo,
        mobile: that.data.mobile,
        bankCardNo: that.data.bankCode

      },
      method: 'POST',
      success: function (res) {
        console.log(res)

        if (res.data.ok) {
          if (res.data.data.rmContent == '签约失败'){
            wx.showModal({
              title: '提示',
              content:'签约成功' ,
              confirmColor: '#7aa6d1',
              showCancel: false
            })
            wx.navigateTo({
              url: '/pages/goyq/goyq',
            })
          }else{
            wx.showModal({
              title: '提示',
              content: '获取数据失败',
              confirmColor: '#7aa6d1',
              showCancel: false
            })
          }
         
          // if(res.data.data.rmContent == "已发送验证码"){
          //     wx.request({
          //         url: pathUrl + '/',
          //     })
          // }

        } else {
          wx.showModal({
            title: '提示',
            content: '获取数据失败',
            confirmColor: '#7aa6d1',
            showCancel: false
          })
        }
      }
    })
  },





  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var openId = wx.getStorageSync('openId');
    this.setData({
      openId: openId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})